package com.fhz.common_lib.mvp.view;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.fhz.common_lib.mvp.presenter.IPresenter;


public abstract class BaseFragment<P extends IPresenter> extends Fragment implements IFragment, IView {

    protected P fragmentPresenter;
    protected View fragmentView;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        fragmentView = inflater.inflate(bindLayout(), container, false);
        return fragmentView;
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        initData();
    }


    @Override
    public <T extends View> T findViewById(int id) {
        return fragmentView.findViewById(id);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (fragmentPresenter != null){
            fragmentPresenter.destroy();
            fragmentPresenter = null;
        }
    }
}
